package com.invengo.module_check.ui.fragment.listing_by_car.item;

import com.invengo.library_db.entity.module_check.BookBean;
import com.invengo.module_check.ui.fragment.listing_by_car.ListingByCarViewModel;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableBoolean;
import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;

public class ListingByCarItemViewModel extends ItemViewModel<ListingByCarViewModel> {
    public SingleLiveEvent<BookBean> book  =new SingleLiveEvent<>();
    public ObservableBoolean isMathcShelf  =new ObservableBoolean(false);

    public ListingByCarItemViewModel(@NonNull ListingByCarViewModel viewModel,BookBean bean) {
        super(viewModel);
        book.postValue(bean);
    }
    public BindingCommand removeItem = new BindingCommand(() -> {
        viewModel.onItemRemove(this);
    });
    public int getPosition() {
        return viewModel.getPosition(this) + 1;
    }

    public int sort(ListingByCarItemViewModel o1,ListingByCarItemViewModel o2){
        return o1.book.getValue().getShelfCode().hashCode() - o2.book.getValue().getShelfCode().hashCode();
    }

    public void checkMatch(String shelfCode) {
        boolean equals = book.getValue().getShelfCode().equals(shelfCode);
        isMathcShelf.set(equals);
    }
}
